package Chapter05.cak;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentGraduateDestinationSystem {
    static ArrayList<Student> students = new ArrayList<Student>();
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            System.out.println("欢迎使用学生毕业走向统计系统！");
            System.out.println("1. 添加学生");
            System.out.println("2. 修改学生");
            System.out.println("3. 删除学生");
            System.out.println("4. 查找学生");
            System.out.println("5. 统计毕业走向");
            System.out.println("6. 退出系统");
            System.out.print("请输入操作编号：");
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    addStudent();
                    break;
                case 2:
                    modifyStudent();
                    break;
                case 3:
                    deleteStudent();
                    break;
                case 4:
                    findStudent();
                    break;
                case 5:
                    countGraduateDestination();
                    break;
                case 6:
                    System.out.println("感谢使用学生毕业走向统计系统！");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入有误，请重新输入！");
                    break;
            }
        }
    }

    public static void addStudent() {
        System.out.print("请输入学生姓名：");
        String name = scanner.next();
        System.out.print("请输入学生学号：");
        String id = scanner.next();
        System.out.print("请输入学生年龄：");
        int age = scanner.nextInt();
        System.out.print("请输入学生性别：");
        String gender = scanner.next();
        System.out.print("请输入学生毕业走向（就业/考研/出国）：");
        String graduateDestination = scanner.next();
        students.add(new Student(name, id, age, gender, graduateDestination));
        System.out.println("添加成功！");
    }

    public static void modifyStudent() {
        System.out.print("请输入要修改的学生学号：");
        String id = scanner.next();
        for (Student student : students) {
            if (student.getId().equals(id)) {
                System.out.print("请输入学生姓名：");
                String name = scanner.next();
                System.out.print("请输入学生年龄：");
                int age = scanner.nextInt();
                System.out.print("请输入学生性别：");
                String gender = scanner.next();
                System.out.print("请输入学生毕业走向（就业/考研/出国）：");
                String graduateDestination = scanner.next();
                student.setName(name);
                student.setAge(age);
                student.setGender(gender);
                student.setGraduateDestination(graduateDestination);
                System.out.println("修改成功！");
                return;
            }
        }
        System.out.println("未找到该学生！");
    }

    public static void deleteStudent() {
        System.out.print("请输入要删除的学生学号：");
        String id = scanner.next();
        for (Student student : students) {
            if (student.getId().equals(id)) {
                students.remove(student);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("未找到该学生！");
    }

    public static void findStudent() {
        System.out.print("请输入要查找的学生学号：");
        String id = scanner.next();
        for (Student student : students) {
            if (student.getId().equals(id)) {
                System.out.println(student.toString());
                return;
            }
        }
        System.out.println("未找到该学生！");
    }

    public static void countGraduateDestination() {
        int jobCount = 0;
        int graduateCount = 0;
        int abroadCount = 0;
        for (Student student : students) {
            switch (student.getGraduateDestination()) {
                case "就业":
                    jobCount++;
                    break;
                case "考研":
                    graduateCount++;
                    break;
                case "出国":
                    abroadCount++;
                    break;
            }
        }
        System.out.println("毕业走向统计结果：");
        System.out.println("就业人数：" + jobCount);
        System.out.println("考研人数：" + graduateCount);
        System.out.println("出国人数：" + abroadCount);
    }
}

class Student {
    private String name;
    private String id;
    private int age;
    private String gender;
    private String graduateDestination;

    public Student(String name, String id, int age, String gender, String graduateDestination) {
        this.name = name;
        this.id = id;
        this.age = age;
        this.gender = gender;
        this.graduateDestination = graduateDestination;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getGraduateDestination() {
        return graduateDestination;
    }

    public void setGraduateDestination(String graduateDestination) {
        this.graduateDestination = graduateDestination;
    }

    @Override
    public String toString() {
        return "姓名：" + name +
                " 学号：" + id +
                " 年龄：" + age +
                " 性别：" + gender +
                " 毕业走向：" + graduateDestination;
    }
}